<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="static/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="static/bootstrap/css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="static/easyui/themes/icon.css">
<link rel="stylesheet" href="static/css/style.css" />
<script src="static/jquery/jquery-1.12.4.js"></script>
<script src="static/bootstrap/js/bootstrap.js"></script>
<script src="static/easyui/jquery.easyui.min.js"></script>
<script src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>资金</title>
</head>
<style>
.modal-header {
    padding: 0 0 10px;
    text-align: center;
}
.modal-title {
    font-size: 16px;
}
.modal-header .close {
    position: absolute;
    right: 10px;
    top: 10px;
}
</style>
<body>
	<div class="container-fluid">
	<div class="row-fluid" >
		<div class="span12">
			<table class="table table-bordered" style="margin-top:10px;">
				<thead>
				<tr>
				</tr>
					<th rowspan=2>类别</th>
					<th colspan=3>预算</th>
					<th colspan=3>申请</th>
					<th colspan=3>执行</th>
				<tr>
					
					<th>总计</th>
					<th>已审核</th>
					<th>未审核</th>
					<th>总计</th>
					<th>已审核</th>
					<th>未审核</th>
					<th>总计</th>
					<th>已审核</th>
					<th>未审核</th>
				</tr>
					
				</thead>
				<tbody id="table">
				</tbody>
			</table>
		</div>
	</div>
</div>
<div class="modal fade" id="proDlg"  role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
            <div class="modal-header">
          <h5 class="modal-title">详情</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">×</span>
          </button>
        </div>
            <table class="table table-bordered" style="margin-top:10px;">
				<thead>
					<th >金额</th>
					<th >内容</th>
					<th >一级审核人</th>
					<th >一级审核日期</th>
					<th >二级审核人</th>
					<th >二级审核日期</th>
				</thead>
				<tbody id="info">
				</tbody>
			</table>
			</div>
            
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
</body>
<script th:inline="javascript">
	var projectitemid = [[${projectitemid}]];

	$(document).ready(function() {
		$.ajax({
			type : 'GET',
			url : "moneyinfo.do?projectitemid=" + projectitemid,
			contentType : "application/json",
			success : function(data) {
				var totalbudgetmoney = 0;
				var totalcapitalmoney = 0;
				var totalexecutemoney = 0;
				$('#table').find('tr').remove();
				$.each(data, function(i,val) {
					var row = '<tr>';
					row += '<td>' + val.content + '</td>';
					if (val.budgetmoney1 + val.budgetmoney2 > 0){
						row += '<td><b>' + (val.budgetmoney1 + val.budgetmoney2).toFixed(2) + '</b></td>';
					}else{
						row += '<td></td>';
					}
					if (val.budgetmoney1 > 0){
						row += '<td><a class="d-btn btn-green" onclick="getbudget(this,' + val.id + ',\'4\'' + ')">'
								+ val.budgetmoney1.toFixed(2) + '</a></td>';
						totalbudgetmoney += Number(val.budgetmoney1);
					}else{
						row += '<td></td>';
					}
					if (val.budgetmoney2 > 0){
						row += '<td><a class="d-btn btn-yellow" onclick="getbudget(this,' + val.id + ',\'6,7\'' + ')">'
								+ val.budgetmoney2.toFixed(2) + '</a></td>';
					}else{
						row += '<td></td>';
					}
					if (val.capitalmoney1 + val.capitalmoney2 > 0){
						row += '<td><b>' + (val.capitalmoney1 + val.capitalmoney2).toFixed(2) + '</b></td>';
					}else{
						row += '<td></td>';
					}
					if (val.capitalmoney1 > 0){
						row += '<td><a class="d-btn btn-green" onclick="getcapital(this,' + val.id + ',\'4\'' + ')">'
								+ val.capitalmoney1.toFixed(2) + '</a></td>';
						totalcapitalmoney += Number(val.capitalmoney1);
					}else{
						row += '<td></td>';
					}
					if (val.capitalmoney2 > 0){
						row += '<td><a class="d-btn btn-yellow" onclick="getcapital(this,' + val.id + ',\'6,7\'' + ')">'
								+ val.capitalmoney2.toFixed(2) + '</a></td>';
					}else{
						row += '<td></td>';
					}
					if (val.executemoney1 + val.executemoney2 > 0){
						row += '<td><b>' + (val.executemoney1 + val.executemoney2).toFixed(2) + '</b></td>';
					}else{
						row += '<td></td>';
					}
					if (val.executemoney1 > 0){
						row += '<td><a class="d-btn btn-green" onclick="getexecute(this,' + val.id + ',\'4\'' + ')">'
								+ val.executemoney1.toFixed(2) + '</a></td>';
						totalexecutemoney += Number(val.executemoney1);
					}else{
						row += '<td></td>';
					}
					if (val.executemoney2 > 0){
						row += '<td><a class="d-btn btn-yellow" onclick="getexecute(this,' + val.id + ',\'6,7\'' + ')">'
								+ val.executemoney2.toFixed(2) + '</a></td>';
					}else{
						row += '<td></td>';
					}
					row += '</tr>';
					$('#table').append(row);
				});
				var html = '<tr><td colspan=4 ><h3>审批预算总额：' + totalbudgetmoney.toFixed(2) + ' ¥</h3></td>'
				html += '<td colspan=6 ><h3>实际开销总额：' + totalcapitalmoney.toFixed(2) + '+' + totalexecutemoney.toFixed(2) + '='
						+ (Number(totalcapitalmoney) + Number(totalexecutemoney)).toFixed(2) + ' ¥</h3></td></tr>';
				$('#table').append(html);
			},
			dataType : "json"
		});
	});
	



	function getbudget(obj,id,status){
		$.ajax({
			type : 'GET',
			url : "getbudget.do",
			data:{projectitemid:projectitemid,itemid:id,status:status},
			contentType : "application/json",
			success : function(data) {
				var tr="";
				$.each(data,function(i,val){
					tr+='<tr><td>'+val.money+'</td>';
					tr+='<td>'+val.content+'</td>';
					if(val.reviewer1){
						tr+='<td>'+val.reviewer1.name+'</td>';
						tr+='<td>'+formatDate(val.level1reviewdate)+'</td>';
					}else{
						tr+='<td></td>';
						tr+='<td></td>';
					}
					if(val.reviewer2){
						tr+='<td>'+val.reviewer2.name+'</td>';
						tr+='<td>'+formatDate(val.level2reviewdate)+'</td>';
					}else{
						tr+='<td></td>';
						tr+='<td></td>';
					}
					tr+='</tr>';
				});
				$('#info').empty();
				$('#info').append(tr);
				$("#proDlg").modal('show');
			}
		});
	}
	function getcapital(obj,id,status){
		$.ajax({
			type : 'GET',
			url : "getcapital.do",
			data:{projectitemid:projectitemid,itemid:id,status:status},
			contentType : "application/json",
			success : function(data) {
				var tr="";
				$.each(data,function(i,val){
					tr+='<tr><td>'+val.money+'</td>';
					tr+='<td>'+val.content+'</td>';
					if(val.reviewer1){
						tr+='<td>'+val.reviewer1.name+'</td>';
						tr+='<td>'+formatDate(val.level1reviewdate)+'</td>';
					}else{
						tr+='<td></td>';
						tr+='<td></td>';
					}
					if(val.reviewer2){
						tr+='<td>'+val.reviewer2.name+'</td>';
						tr+='<td>'+formatDate(val.level2reviewdate)+'</td>';
					}else{
						tr+='<td></td>';
						tr+='<td></td>';
					}
					tr+='</tr>';
				});
				$('#info').empty();
				$('#info').append(tr);
				$("#proDlg").modal('show');
			}
		});
	}
	function getexecute(obj,id,status){
		$.ajax({
			type : 'GET',
			url : "getexecute.do",
			data:{projectitemid:projectitemid,itemid:id,status:status},
			contentType : "application/json",
			success : function(data) {
				var tr="";
				$.each(data,function(i,val){
					tr+='<tr><td>'+val.money+'</td>';
					tr+='<td>'+val.content+'</td>';
					if(val.reviewer1){
						tr+='<td>'+val.reviewer1.name+'</td>';
						tr+='<td>'+formatDate(val.level1reviewdate)+'</td>';
					}else{
						tr+='<td></td>';
						tr+='<td></td>';
					}
					if(val.reviewer2){
						tr+='<td>'+val.reviewer2.name+'</td>';
						tr+='<td>'+formatDate(val.level2reviewdate)+'</td>';
					}else{
						tr+='<td></td>';
						tr+='<td></td>';
					}
					tr+='</tr>';
				});
				$('#info').empty();
				$('#info').append(tr);
				$("#proDlg").modal('show');
			}
		});
	}
	
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(), month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(), hour = date.getHours(), min = date.getMinutes(), sec = date
				.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}

</script>
<style>
.table th, .table td { 
text-align: center;
vertical-align: middle!important;
}
.modal-backdrop{z-index:0;}
</style>

</html>